package com.jwm.power.controller;

import com.jwm.power.util.WebSocketServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

//  测试类
@Controller
@RequestMapping("/test")
public class TestController {
    @Autowired
    private WebSocketServer webSocketServer;
    /**
     * 向用户一推送数据
     * @param msg
     * @return
     */
    @GetMapping("/yonghu1")
    public Map<String,Object> yonghu1(String msg) {
        Map<String, Object> map = new HashMap<>();
        try {
            webSocketServer.sendtoUser(msg, "1");
            map.put("id", 1);
            map.put("msg", msg);
            map.put("status", 0);
        } catch (IOException e) {
            e.printStackTrace();
            map.put("id", 1);
            map.put("msg", msg);
            map.put("status", 1);
        }
        return map;
    }
}
